package com.atjava.nebula.core.tablexml.view;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;

import com.atjava.jox.annotation.ClassProps;
import com.atjava.jox.annotation.FieldProps;
import com.atjava.jox.annotation.FieldProps.ElementType;
import com.atjava.nebula.core.util.io.FileSystemUtil;

@ClassProps(alias = "view-config")
public class ViewConfig implements Serializable {
	
	@FieldProps(alias = "main-view",type = ElementType.ELEMENT)
	private MainView mainView;
	
	@FieldProps(type = ElementType.ELEMENTLIST)
	private List<ModalView> modalViews;
	
	private boolean hasTreeTable;
	
	private String source;

	public MainView getMainView() {
		return mainView;
	}

	public void setMainView(MainView mainView) {
		this.mainView = mainView;
	}

	public boolean isHasTreeTable() {
		return hasTreeTable;
	}

	public void setHasTreeTable(boolean hasTreeTable) {
		this.hasTreeTable = hasTreeTable;
	}

	public ViewConfig clone(){
		
		Object cloneObj = null;
		ByteArrayOutputStream baos = null;
		ByteArrayInputStream bais = null;
		ObjectOutputStream oos = null;
		ObjectInputStream ois = null;
		try{
			baos = new ByteArrayOutputStream();
			oos = new ObjectOutputStream(baos);
			oos.writeObject(this);
			
			bais = new ByteArrayInputStream(baos.toByteArray());
			ois = new ObjectInputStream(bais);
			cloneObj = ois.readObject();
		
		} catch (Exception e){
			e.printStackTrace();
		} finally{
			FileSystemUtil.close(baos);
			FileSystemUtil.close(bais);
			FileSystemUtil.close(oos);
			FileSystemUtil.close(ois);
		}
		return (ViewConfig) cloneObj;
	}

	public List<ModalView> getModalViews() {
		return modalViews;
	}

	public void setModalViews(List<ModalView> modalViews) {
		this.modalViews = modalViews;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

}
